package com.ruoyi.wq.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.Condition;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wq.mapper.WqUserPlayMapper;
import com.ruoyi.wq.domain.WqUserPlay;
import com.ruoyi.wq.domain.vo.WqUserPlayVO;
import com.ruoyi.wq.service.IWqUserPlayService;

/**
 * 达人陪玩Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-09-05
 */
@Service
public class WqUserPlayServiceImpl extends ServiceImpl<WqUserPlayMapper, WqUserPlay> implements IWqUserPlayService {

    @Autowired
    private WqUserPlayMapper wqUserPlayMapper;

    /**
     * 查询达人陪玩
     * 
     * @param id 达人陪玩主键
     * @return 达人陪玩
     */
    @Override
    public WqUserPlay selectWqUserPlayById(String id)
    {
        return wqUserPlayMapper.selectWqUserPlayById(id);
    }

    /**
     * 查询达人陪玩列表
     * 
     * @param wqUserPlay 达人陪玩
     * @return 达人陪玩
     */
    @Override
    public List<WqUserPlay> selectWqUserPlayList(WqUserPlay wqUserPlay)
    {
        return wqUserPlayMapper.selectWqUserPlayList(wqUserPlay);
    }

    /**
     * 新增达人陪玩
     * 
     * @param wqUserPlay 达人陪玩
     * @return 结果
     */
    @Override
    public int insertWqUserPlay(WqUserPlay wqUserPlay)
    {
        wqUserPlay.setCreateTime(DateUtils.getNowDate());
        return wqUserPlayMapper.insertWqUserPlay(wqUserPlay);
    }

    /**
     * 修改达人陪玩
     * 
     * @param wqUserPlay 达人陪玩
     * @return 结果
     */
    @Override
    public int updateWqUserPlay(WqUserPlay wqUserPlay)
    {
        wqUserPlay.setUpdateTime(DateUtils.getNowDate());
        return wqUserPlayMapper.updateWqUserPlay(wqUserPlay);
    }

    /**
     * 批量删除达人陪玩
     * 
     * @param ids 需要删除的达人陪玩主键
     * @return 结果
     */
    @Override
    public int deleteWqUserPlayByIds(String[] ids)
    {
        return wqUserPlayMapper.deleteWqUserPlayByIds(ids);
    }

    /**
     * 删除达人陪玩信息
     * 
     * @param id 达人陪玩主键
     * @return 结果
     */
    @Override
    public int deleteWqUserPlayById(String id)
    {
        return wqUserPlayMapper.deleteWqUserPlayById(id);
    }

	@Override
	public boolean saveUserPlay(WqUserPlay wqUserPlay) {
		QueryWrapper<WqUserPlay> queryWrapper = new QueryWrapper<>();
		WqUserPlay entity = new WqUserPlay();
		entity.setUserId(SecurityUtils.getUserId());
		entity.setPlayId(wqUserPlay.getPlayId());
		queryWrapper.setEntity(entity);
		entity = baseMapper.selectOne(queryWrapper);
		if(entity == null){
			entity = new WqUserPlay();
			entity.setUserId(SecurityUtils.getUserId());
			entity.setPlayId(wqUserPlay.getPlayId());
			entity.setGameRemark(wqUserPlay.getGameRemark());
			baseMapper.insert(entity);
		}else{
			entity.setGameRemark(wqUserPlay.getGameRemark());
			entity.setStatus(wqUserPlay.getStatus());
			baseMapper.updateById(entity);
		}
		return true;
	}

	@Override
	public TableDataInfo getPageList(WqUserPlayVO wqUserPlay) {
		IPage<WqUserPlayVO> page = baseMapper.selectPageList(Condition.getPage(wqUserPlay), wqUserPlay);
		return Condition.getTableDataInfo(page.getRecords(), page.getTotal());
	}

	@Override
	public List<WqUserPlayVO> getPlayList(Long userId) {
		return baseMapper.getPlayList(userId);
	}

	@Override
	public TableDataInfo getUserPageList(WqUserPlayVO wqUserPlay) {
		IPage<WqUserPlayVO> page = baseMapper.selectUserPageList(Condition.getPage(wqUserPlay), wqUserPlay);
		return Condition.getTableDataInfo(page.getRecords(), page.getTotal());
	}
}
